import { _decorator, AudioSource, Component, instantiate, Node, UITransform } from 'cc';
import { ResManager } from '../../../core/modules/res/resManager';
import { G_VIEW_SIZE } from '../../../../Boots/Boost';
import { AudioManager } from '../../../core/modules/audio/AudioManager';
import { LoginAudio } from './LoginAudio';
const { ccclass, property } = _decorator;

@ccclass('LoginEntry')
export class LoginEntry extends Component {
    start() {

        //load BG Music
        AudioManager.getInstance().playMusic(LoginAudio.bgm)
        this.autoLogin();

            // ResManager.getInstance().loadAudioClip("Match3BN", "audio/background", audioClip => {
            //     let audioSource = this.node.addComponent(AudioSource);
            //     audioSource.clip = audioClip;
            //     audioSource.loop = true;
            //     audioSource.play();
            // })



            
            // ResManager.getInstance().loadPrefab("Match3BN","match3",prefab => {
            //     let match3Node = instantiate(prefab)
            //     this.node.addChild(match3Node)
            //     match3Node.getComponent(UITransform).setContentSize(G_VIEW_SIZE.clone());
            // })


    }

    autoLogin(){

        this.scheduleOnce(() =>{
            this.onLoginSuccess();
        },1)

    }

    async onLoginSuccess(){

        await ResManager.getInstance().loadBundleAsync("Match3BN");
        let match3Entry = this.node.addComponent("Match3Entry");
        (match3Entry as any).init()


        // ResManager.getInstance().loadBundle("Match3BN",() => {
        //     let match3Entry = this.node.addComponent("Match3Entry");
        //     (match3Entry as any).init()
        // })
    }

    update(deltaTime: number) {
        
    }
}


